package com.zxk.handler;

import com.sun.jna.platform.win32.User32;
import com.sun.jna.platform.win32.WinDef;
import com.zxk.controller.TaskController;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 任务处理器，主要对控制层进行组合
 *
 * @author: 舟小亢
 * @date: 2023-08-05 22:28
 */
public class TaskHandler implements Runnable {

    private static Logger LOG = LoggerFactory.getLogger(TaskHandler.class);

    /**
     * 截图时用句柄
     */
    private WinDef.HWND hwnd_0;

    /**
     * 执行键鼠命令时用句柄
     */
    private WinDef.HWND hwnd_1;

    /**
     * 备用句柄
     */
    private WinDef.HWND hwnd_2;

    public TaskHandler(WinDef.HWND hwnd_0, WinDef.HWND hwnd_1, WinDef.HWND hwnd_2, int x, int y) {
        // 初始化句柄,第一个参数是Windows窗体的窗体类，第二个参数是窗体的标题
        this.hwnd_0 = hwnd_0;
        this.hwnd_1 = hwnd_1;
        this.hwnd_2 = hwnd_2;

        // 调整位置
        WinDef.RECT rect = new WinDef.RECT();
        User32.INSTANCE.GetWindowRect(this.hwnd_0, rect);
        LOG.info("屏幕长{},宽{}", rect.right - rect.left, rect.bottom - rect.top);
        User32.INSTANCE.SetWindowPos(this.hwnd_0, null, x, y, 968, 589, 0);
        LOG.info("重置长968,宽589");
    }

    @Override
    public void run() {
        try {
            // 调度任务
            new TaskController(hwnd_0, hwnd_1, hwnd_2);
        } catch (Exception e) {
            LOG.error("catch exception", e);
        }
    }
}
